package cn.com.w.mybatisplus.service.impl;

import cn.com.w.mybatisplus.domain.UserInfo;
import cn.com.w.mybatisplus.dao.UserInfoMapper;
import cn.com.w.mybatisplus.service.IUserInfoService;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhangxiaolong
 * @since 2022-06-22
 */
@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements IUserInfoService {


    @Override
    @Transactional
    public void updateTest() throws RuntimeException {
        UserInfo byId = this.getById(1539133380694659073L);
        System.out.println("值1=" + JSONObject.toJSONString(byId));
        byId.setUserName("修改值xxxx");
        this.updateById(byId);

        try {
            int i = 1/0;
        } catch (Exception e) {
            System.out.println("值2=" + JSONObject.toJSONString(byId));
            throw new RuntimeException();
        }
    }

    @Override
    public UserInfo getOneByNo(Long userN0) {
        LambdaQueryWrapper<UserInfo> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(UserInfo::getUserNo, userN0);
        queryWrapper.last(" limit 1");
        return this.getOne(queryWrapper);
    }
}
